{extend name="sitehome@style/base"/}
{block name="resources"}
{/block}
{block name="main"}

<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
    <ul class="layui-tab-title">
        <li><a href="{:addon_url('Sns://sitehome/info/categorymanage')}?category_id={$category_id}">编辑</a></li>
        <li class="layui-this" ><a href="{:addon_url('Sns://sitehome/info/categoryattributelist')}?category_id={$category_id}">属性</a></li>
        <li><a href="{:addon_url('Sns://sitehome/info/categorysettings')}?category_id={$category_id}">设置</a></li>
    </ul>
    <div class="layui-tab-content" style="height: 100px;">
        <div class="layui-tab-item layui-show">

        <table class="layui-table" id="info_list" lay-filter="info_list" ></table>
        <div class="nc-functional-block">
            <button class="layui-btn" onclick="location.href='{:addon_url('Sns://sitehome/info/addCategoryAttribute')}?category_id={$category_id}'";>添加属性</button>
        </div>
        <div class="layui-form">
            <table class="layui-table">
                <colgroup>
                    <col width="20%">
                    <col width="20%">
                    <col width="20%">
                    <col width="15">
                    <col width="25%">
                </colgroup>
                <thead>
                <tr>
                    <th><div class="layui-table-cell">名称</div></th>
                    <th><div class="layui-table-cell">分类</div></th>
                    <th><div class="layui-table-cell">排序</div></th>
                    <th><div class="layui-table-cell">是否可搜索</div></th>
                    <th><div class="layui-table-cell" style="text-align: right;">操作</div></th>
                </tr>
                </thead>
                <tbody class="layui-table-body">
                {foreach name="list['data']" item="vo" key="k"}
                <tr>
                    <td>
                        <div class="layui-table-cell">
                            <span>{$vo.name}</span>
                        </div>
                    </td>
                    <td>
                        <div class="layui-table-cell">
                            <span>{$vo.category_name}</span>
                        </div>
                    </td>
                    <td>
                        <div class="layui-table-cell">
                                <input type="text" name="sort"  lay-skin="switch" value="{$vo.sort}" lay-filter="sort" style="width:60px" onchange="updataSort({$vo.attribute_id},this)" class="sort layui-input">
                        </div>
                    </td>
                    <!-- disabled class="layui-input layui-disabled" -->
                    <td>
                        <div class="layui-table-cell">
                            <input type="checkbox" name="screening_show"  lay-skin="switch" value="{$vo['attribute_id']}" lay-filter="screening_show"  {if $vo['screening_show'] == 1}checked{/if}>
                        </div>
                    </td>
                    <td>
                        <div class="layui-table-cell" style="text-align: right;">
                            <a class="default"  href="javascript:;" onclick="location.href='{:addon_url('Sns://sitehome/info/editCategoryAttribute')}?attribute_id={$vo.attribute_id}'";>编辑</a>
                            <a class="default" href='javascript:edit({$vo|json_encode});' onclick="del({$vo['attribute_id']})">删除</a>
                        </div>
                    </td>
                </tr>
                {/foreach}
                </tbody>
            </table>
        </div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script>
    //搜索启用禁用
    layui.use(['form', 'laytpl', 'element'], function(){
        var form = layui.form;
        form.on('switch(screening_show)', function(data){

            var attribute_id = data.value;
            var screening_show = data.elem.checked ? 1 : 0;

            $.ajax({
                type : "post",
                url : nc.url("sns://sitehome/info/isCategoryAttribute"),
                dataType : "JSON",
                data : {
                    'screening_show' : screening_show,
                    'attribute_id' : attribute_id
                },
                success : function(res) {
                }
            });
            return false;
        });  
    });

   
    //排序更新
    function updataSort(attribute_id,_this){

        var sort = $(_this).val();

        // console.log(sort);return;
    
        $.ajax({
            type: "post",
            url: nc.url("sns://sitehome/info/isCategoryupdateSort"),
            data: {
                'attribute_id' : attribute_id,
                'sort': sort,
            },
            dataType: "JSON",
            success: function (res) {
            }
        });
    }

    //删除
    function del(attributeId){
        layer.confirm('确定删除吗?', {
            btn: ['确定', '取消']
        }, function () {
            $.ajax({
                type: "post",
                url: nc.url("sns://sitehome/info/delCategoryAttribute"),
                data: {
                    'attributeId': attributeId,
                },
                dataType: "JSON",
                success: function (res) {
                    layer.msg(res.message);
                    location.reload();
                }
            });
        }, function () {
            layer.close();
        });

    }
</script>
{/block}